const globalPopup = {
  state: {
    visible: false,
    message: "",
    delay: ""
  },
  mutations: {
    OPENPOPUP(state, { message, delay}) {
      state.visible = true;
      state.message = message;
      state.delay = delay;
    },
    CLOSEPOPUP(state) {
      state.visible = false;
    }
  },
  actions: {
    openPopup({ commit }, { message, delay = 2000 } = {}) {
      if (!message) return;
      commit("OPENPOPUP", { message, delay })
    }
  }
};

export default globalPopup;
